import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_advanced_btn.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_advanced_center_arrow.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_advanced_item.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_advanced_title.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/archives/archives_upgrade_attr.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/constants/font_weight.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_add_attr_entity.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/achieves/archieves_weapon_entity.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';

//武器形态升级界面
class ArchivesAdvancedCenterWidget extends StatelessWidget {
  final ArchievesWeaponEntity archievesWeaponEntity;

  const ArchivesAdvancedCenterWidget({Key key, this.archievesWeaponEntity})
      : super(key: key);

  List<Widget> createItem(int count) {
    return List<Widget>.generate(count, (index) {
      ArchievesWeaponUpgradegood good = archievesWeaponEntity?.formUpgradeGoods[index];
      if (good.goodsType == 4) {
        return Container();
      }
      return Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Container(
            width: setRatio(50),
            height: setRatio(50),
            child: Stack(
              children: <Widget>[
                Container(
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: NetworkImage(
                              '${good?.picUrl ?? ''}')),
                      borderRadius: BorderRadius.circular(setRatio(2))),
                ),
                Positioned(
                  bottom: 0,
                  child: Container(
                    height: setRatio(13),
                    width: setRatio(50),
                    decoration: BoxDecoration(
                        color: Color(0x9F000000),
                        borderRadius: BorderRadius.only(
                            bottomLeft: Radius.circular(setRatio(2)),
                            bottomRight: Radius.circular(setRatio(2)))),
                    child: Center(
                      child: Text(
                        '${good?.userNum ?? 0}/${good?.num ?? 0}',
                        style: TextStyle(
                            decoration: TextDecoration.none,
                            color: Color(0xFFFFFFFF),
                            fontFamily: FontFamily.PINGFANG,
                            fontWeight: FontWeightCustom.PF_Medium,
                            fontSize: setTextSp(9)),
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
          SizedBox(height: setRatio(5)),
          Text(
            '${good?.name ?? ''}',
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
                decoration: TextDecoration.none,
                color: Color(0xFFEFF0F8),
                fontFamily: FontFamily.PINGFANG,
                fontWeight: FontWeightCustom.PF_Medium,
                fontSize: setTextSp(10)),
          )
        ],
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    ArchievesAddAttrEntity addattr =  ArchievesAddAttrEntity(hp: 0,res:0,def: 0,atk: 0);
    if (archievesWeaponEntity.nextForm != null) {
      addattr = ArchievesAddAttrEntity(
        hp: archievesWeaponEntity.nextForm.hp - archievesWeaponEntity.currentForm.hp,
        def: archievesWeaponEntity.nextForm.def - archievesWeaponEntity.currentForm.def,
        atk: archievesWeaponEntity.nextForm.atk - archievesWeaponEntity.currentForm.atk,
        res: archievesWeaponEntity.nextForm.res - archievesWeaponEntity.currentForm.res,
      );
    }

    return Container(
      width: setRatio(360),
      height: setRatio(432),
      margin: EdgeInsets.only(left: setRatio(7.5), top: setRatio(9)),
      decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage(imageUtilYeXiu(
                  'archives/icon_archivers_advanced_center_bg@3x')))),
      child: Stack(
        overflow: Overflow.visible,
        children: <Widget>[
          Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(
                    left: setRatio(22), top: setRatio(22), right: setRatio(22)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      ArchivesAdvancedItemWidget(
                        lock: false,form: archievesWeaponEntity.currentForm,
                      ),
                      ArchivesAdvancedCenterArrowWidget(weaponEntity: archievesWeaponEntity),
                      ArchivesAdvancedItemWidget(
                          lock: true,form : archievesWeaponEntity.nextForm
                      ),
                    ],
                  ),
              ),
              SizedBox(
                height: setRatio(25),
              ),
              ArchivesUpgradeAttrWidget(info: addattr),
              Container(
                width: setRatio(360),
                padding: EdgeInsets.only(
                    left: setRatio(30), right: setRatio(30), top: setRatio(23)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: createItem(archievesWeaponEntity.upgradeGoods.length),
                ),
              )
            ],
          ),
          ArchivesAdvancedTitleWidget(),
          ArchivesAdvancedBtnWidget(archievesWeaponEntity: archievesWeaponEntity)
        ],
      ),
    );
  }
}
